from operator import mod
from time import sleep
from zlib import *
from threading import Thread
from socket import (SO_RCVLOWAT, socket, AF_INET, SOCK_DGRAM, SOL_SOCKET, SO_BROADCAST)
from PIL import Image
 
#1、创建一个udp套接字
 
udp_socket=socket(AF_INET,SOCK_DGRAM)
 
#2、绑定本地相关信息，如果不绑定，则随机分配
 
local_addr = ('', 22222)#ip地址和端口号，IP不写表示本机任何一个ip
 
udp_socket.bind(local_addr)
 
#3、等待接收对方发送的数据


recv_data = udp_socket.recvfrom(1024)#1024表示本次接收的最大字节

#recv_data存储的是一个元组（发送方ip，Port）

send_addr = recv_data[1]
recv_msg = recv_data[0]
if recv_msg == b'start':

    print("Receive start")

    is_over = True
    data = b''
    while is_over:
        recv_data = udp_socket.recvfrom(1024)   #1024表示本次接收的最大字节
        
        if recv_data[0].startswith(b'_over'):
            
            print("Receive over")
            is_over = False

        if is_over != False:

            data += recv_data[0]

    data = decompress(data)
    # print(data, end='')
    img = Image.frombytes(mode= "RGBA", size=(2880, 1800), data=data, decoder_name="raw")

    img.show()
 
udp_socket.close()